package com.niuniu.rushdorm.service.impl;

import com.niuniu.rushdorm.mapper.UserInfoMapper;
import com.niuniu.rushdorm.mapper.UserMapper;
import com.niuniu.rushdorm.pojo.entity.User;
import com.niuniu.rushdorm.pojo.vo.UserVO;
import com.niuniu.rushdorm.service.StudentService;
import com.niuniu.rushdorm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Meng
 * 2022/11/24
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    StudentService studentService;
    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public UserVO getUser(Long uid) {
        UserVO userVO = userMapper.getUser(uid);
        if(userVO.getType().equals(UserVO.STUDENT)){
            userVO.setStudent(studentService.getStudentByUid(uid));
        }
        return userVO;
    }

    @Override
    public void updateLoginTime(UserVO userVO) {
        userMapper.updateLoginTime(userVO.getUid(),userVO.getLastLoginTime());
    }

    @Override
    public User GetUserById(long id) {
        return userInfoMapper.GetUserById(id);
    }
}
